import request from "@/utils/request";
const DEVICE_BASE_URL = "/devices";

const DeviceAPI = {
  getList(queryParams: DevicePageQuery) {
    return request<any, PageResult<DevicePageVO[]>>({
      url: `${DEVICE_BASE_URL}/list`,
      method: "get",
      params: queryParams,
    });
  },
  getFormData(id: number) {
    return request({
      url: `${DEVICE_BASE_URL}/getDeviceById/${id}`,
      method: "get",
    });
  },

  add(data: DeviceForm) {
    data.deviceSnId = data.deviceSnId?.toUpperCase();
    return request({
      url: `${DEVICE_BASE_URL}/create`,
      method: "post",
      data: data,
    });
  },

  update(data: DeviceForm) {
    data.deviceSnId = data.deviceSnId?.toUpperCase();
    return request({
      url: `${DEVICE_BASE_URL}/update`,
      method: "POST",
      data: data,
    });
  },

  saveGateway(data: any) {
    return request({
      url: `${DEVICE_BASE_URL}/saveGateway`,
      method: "POST",
      data: data,
    });
  },

  deleteByIds(ids: string) {
    return request({
      url: `${DEVICE_BASE_URL}/delete/${ids}`,
      method: "get",
    });
  },

  getIdleDevce() {
    return request<any, any>({
      url: `${DEVICE_BASE_URL}/getIdleDevices`,
      method: "get",
    });
  },
  getLocationBindDevices(localId: number) {
    return request<any, any>({
      url: `${DEVICE_BASE_URL}/getLocationBindDevices/${localId}`,
      method: "get",
    });
  },

  countDevicesByType() {
    return request<any, any>({
      url: `${DEVICE_BASE_URL}/countTotalByDeviceType`,
      method: "get",
    });
  },
};

export default DeviceAPI;
export interface DevicePageVO {
  deviceId: number;
  deviceSnId: string;
  deviceType: string;
  deviceRemark: string;
  deviceStatus: string;
  batteryStatus: number;
  checkHealth: number;
  createAt: Date;
  updatedAt: Date;
}

export interface DevicePageQuery extends PageQuery {
  keywords?: string;
  deviceType?: string;
}
export interface DeviceForm {
  deviceId?: number;
  deviceSnId?: string;
  deviceRemark?: string;
  deviceType?: string;
}
